<?php

/**
 * This is the model class for table "master_akun".
 *
 * The followings are the available columns in table 'master_akun':
 * @property integer $ID_AKUN
 * @property string $NAMA_AKUN
 * @property integer $KODE
 * @property integer $ID_KEL_AKUN
 * @property double $PAJAK
 * @property double $SALDO_AWAL
 * @property double $SALDO
 * @property string $KETERANGAN
 */
class MasterAkun extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MasterAkun the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'master_akun';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NAMA_AKUN, KODE, ID_KEL_AKUN', 'required'),
			array('KODE, ID_KEL_AKUN', 'numerical', 'integerOnly'=>true),
			array('PAJAK, SALDO_AWAL, SALDO', 'numerical'),
			array('NAMA_AKUN', 'length', 'max'=>30),
			array('KETERANGAN', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_AKUN, NAMA_AKUN, KODE, ID_KEL_AKUN, PAJAK, SALDO_AWAL, SALDO, KETERANGAN', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'kelompok'=>array(self::HAS_ONE,'KelompokAkun',array('ID_KEL_AKUN'=>'ID_KEL_AKUN')),
			'masterParent'=>array(self::BELONGS_TO,'MasterAkun',array('ID_KEL_AKUN'=>'KODE')),
			// 'masterChild'=>array(self::HAS_MANY,'MasterAkun',array('KODE'=>'ID_KEL_AKUN')),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_AKUN' => 'Id Akun',
			'NAMA_AKUN' => 'Nama Akun',
			'KODE' => 'Kode',
			'ID_KEL_AKUN' => 'Kelompok Akun',
			'PAJAK' => 'Pajak',
			'SALDO_AWAL' => 'Saldo Awal',
			'SALDO' => 'Saldo',
			'KETERANGAN' => 'Keterangan',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_AKUN',$this->ID_AKUN);
		$criteria->compare('NAMA_AKUN',$this->NAMA_AKUN,true);
		$criteria->compare('KODE',$this->KODE);
		$criteria->compare('ID_KEL_AKUN',$this->ID_KEL_AKUN);
		$criteria->compare('PAJAK',$this->PAJAK);
		$criteria->compare('SALDO_AWAL',$this->SALDO_AWAL);
		$criteria->compare('SALDO',$this->SALDO);
		$criteria->compare('KETERANGAN',$this->KETERANGAN,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}